package com.tsingteng.cosfun.widget.dialog.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.tsingteng.cosfun.R;
import com.tsingteng.cosfun.app.AppContext;
import com.tsingteng.cosfun.bean.VideoSectionBean;
import com.tsingteng.cosfun.utils.ImageUtils;
import com.tsingteng.cosfun.utils.StringUtils;

import java.util.List;

/**
 * Created by Administrator on 2017/3/13 0013.
 * E-Mail：543441727@qq.com
 */

public class VideoOrderAdapter extends RecyclerView.Adapter<VideoOrderAdapter.ViewHolder> {

    private List<VideoSectionBean> datas;
    private Context mContext;
    private LayoutInflater mLiLayoutInflater;

    public VideoOrderAdapter(List<VideoSectionBean> datas, Context context) {
//        setHasStableIds(true);
        this.datas = datas;
        this.mContext = context;
        this.mLiLayoutInflater = LayoutInflater.from(mContext);
    }


    @Override
    public VideoOrderAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(mLiLayoutInflater.inflate(R.layout.item_order_dialog_adapter, parent, false));
    }

    @Override
    public void onBindViewHolder(VideoOrderAdapter.ViewHolder holder, int position) {
        holder.mTvNumber.setText(String.valueOf(position+1));
        VideoSectionBean videoSectionBean = datas.get(position);
        Object tag = holder.mVideoCover.getTag();
//            holder.mVideoCover.setTag(String.valueOf(System.currentTimeMillis()));
            ImageUtils.LoadImage(AppContext.getContext(), videoSectionBean.getUrlCover(),holder.mVideoCover,R.drawable.add_fragment);

//        if (videoSectionBean.getUrlCover() != null) {
//            ImageUtils.LoadImage(AppContext.getContext(), videoSectionBean.getUrlCover(),holder.mVideoCover,R.drawable.add_fragment);
//        }else {
//            ImageUtils.LoadImage(AppContext.getContext(),"",holder.mVideoCover,R.drawable.add_fragment);
//        }
        holder.mTvTime.setText(StringUtils.div(videoSectionBean.getSectionStartPoint(),1000,1)+ "-"+StringUtils.div(videoSectionBean.getSectionEndPoint(),1000,1));
    }

//    @Override
//    public long getItemId(int position) {
//        return datas.get(position).getSectionVideoSpan();
//    }

    @Override
    public int getItemCount() {
        return datas == null ? 0 : datas.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView mTvNumber;
        ImageView mVideoCover;
        TextView mTvTime;

        public ViewHolder(View itemView) {
            super(itemView);
            mTvNumber = (TextView) itemView.findViewById(R.id.tv_number);
            mVideoCover = (ImageView) itemView.findViewById(R.id.iv_video_cover);
            mTvTime = (TextView) itemView.findViewById(R.id.tv_time);}
    }
}
